import { color } from '../config';
import { Points } from './points'
import * as THREE from 'three'

export class Fly{
  constructor(scene,time,sourcePoints,targetPoints){
    this.scene = scene
    this.time = time
    console.log();
    this.options = {
      // 起始点
      source:sourcePoints,
      // 终止点
      target:targetPoints,
      range:200,
      height:300,
      color:color.fly,
      size:30,
      len:0
    }
    const source = new THREE.Vector3(
      this.options.source.x,
      this.options.source.y,
      this.options.source.z,
      )
    const target = new THREE.Vector3(
      this.options.target.x,
      this.options.target.y,
      this.options.target.z,
      )
      // 通过起始点和终止点计算中心位置
      const center = target.clone().lerp(source,0.5)
      // 设置中心位置的高度
      center.y +=this.options.height
      // 计算起点到终点的距离
      this.options.len = parseInt(source.distanceTo(target))
      // 添加贝塞尔曲线运动
      const curve = new THREE.QuadraticBezierCurve3(
        source,center,target
      )
      // 获取粒子
      const points = curve.getPoints(this.options.len) 
    new Points(scene, time).createPoints(this.options,points)
  }

}